package com.example.home.active_function;

import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.widget.ImageView;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;

import com.bumptech.glide.Glide;
import com.example.home.R;
import com.example.home.tool.OKHttpTool;

import static com.example.home.tool.StaticActi.ip;

public class DetailActivity extends AppCompatActivity {
    private String beanId;
    private TextView categoryName;
    private ImageView imgUrl;
    private TextView name;
    private TextView signupNum;
    private TextView likeNum;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_detail);
        Intent intent = getIntent();
        beanId = intent.getStringExtra("item_id");
        initView();
        getData();
    }

    private void getData() {
        OKHttpTool.doNetRequest("prod-api/api/activity/activity/" + beanId,
                OKHttpTool.GET,
                ParticularsBean.class,
                new OKHttpTool.NetCallback() {
                    @Override
                    public void onSuccess(Object obj) {
                        ParticularsBean particularsBean = (ParticularsBean) obj;
                        runOnUiThread(new Runnable() {
                            @Override
                            public void run() {
                                Glide.with(DetailActivity.this).load(ip + particularsBean.getData().getImgUrl()).into(imgUrl);
                                categoryName.setText(particularsBean.getData().getCategoryName());
                                name.setText(particularsBean.getData().getName());
                                signupNum.setText("报名人数:" + particularsBean.getData().getSignupNum());
                                likeNum.setText("点赞数:" + particularsBean.getData().getLikeNum());
                            }
                        });
                    }

                    @Override
                    public void onFailure(String msg) {
                        Log.v("xhf1", "访问失败");
                    }
                }
        );
    }


    private void initView() {
        categoryName = findViewById(R.id.categoryName);
        imgUrl = findViewById(R.id.imgUrl);
        name = findViewById(R.id.name);
        signupNum = findViewById(R.id.signupNum);
        likeNum = findViewById(R.id.likeNum);
    }
}